<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta
      name="description"
      content="An enterprise-class UI design language and React-based implementation with a set of high-quality React components, one of best React UI library for enterprises"
    />
    <title>{% if title %}{{ title }}{% else %}Choerodon UI - A UI Design Language{% endif %}</title>
    <!-- Polyfills -->
    <!--[if IE]>
      <script src="https://as.alipayobjects.com/g/component/??es6-shim/0.35.1/es6-sham.min.js,es6-shim/0.35.1/es6-shim.min.js"></script>
    <![endif]-->
    <script>
      (function() {
        function isLocalStorageNameSupported() {
          var testKey = 'test';
          var storage = window.localStorage;
          try {
            storage.setItem(testKey, '1');
            storage.removeItem(testKey);
            return true;
          } catch (error) {
            return false;
          }
        }

        // 优先级提高到所有静态资源的前面，语言不对，加载其他静态资源没意义
        var pathname = location.pathname;

        function isZhCN(pathname) {
          return /-cn\/?$/.test(pathname);
        }

        function getLocalizedPathname(path, zhCN) {
          var pathname = path.indexOf('/') === 0 ? path : '/' + path;
          if (!zhCN) {
            // to enUS
            return /\/?index-cn/.test(pathname) ? '/' : pathname.replace('-cn', '');
          } else if (pathname === '/') {
            return '/index-cn';
          } else if (pathname.endsWith('/')) {
            return pathname.replace(/\/$/, '-cn/');
          }
          return pathname + '-cn';
        }

        // 兼容旧的 URL， `?locale=...`
        var queryString = location.search;
        if (queryString) {
          var isZhCNConfig = queryString.indexOf('zh-CN') > -1;
          if (isZhCNConfig && !isZhCN(pathname)) {
            location.pathname = getLocalizedPathname(pathname, isZhCNConfig);
          }
        }

        if (isLocalStorageNameSupported() && (pathname === '/' || pathname === '/index-cn')) {
          var lang =
            (window.localStorage && localStorage.getItem('locale')) ||
            ((navigator.language || navigator.browserLanguage).toLowerCase() === 'zh-cn'
              ? 'zh-CN'
              : 'en-US');
          // safari is 'zh-cn', while other browser is 'zh-CN';
          if ((lang === 'zh-CN') !== isZhCN(pathname)) {
            location.pathname = getLocalizedPathname(pathname, lang === 'zh-CN');
          }
        }
        document.documentElement.className += isZhCN(pathname) ? 'zh-cn' : 'en-us';

        if (!window.Intl) {
          var intlPath = 'https://as.alipayobjects.com/g/component/intl/1.0.1/??Intl.min.js';
          if (isZhCN(pathname)) {
            intlPath += ',locale-data/jsonp/zh.js';
          } else {
            intlPath += ',locale-data/jsonp/en.js';
          }
          document.writeln('<script src="' + intlPath + '">' + '<' + '/script>');
        }
        if (!window.Promise) {
          document.writeln(
            '<script src="https://as.alipayobjects.com/g/component/es6-promise/3.2.2/es6-promise.min.js"' +
              '>' +
              '<' +
              '/' +
              'script>',
          );
        }
      })();
    </script>
    <link rel="icon" href="http://choerodon.io/img/favicon.ico" type="image/x-icon" />
    {% for cssFile in manifest["css"] %}
    <link rel="stylesheet" type="text/css" href="{{ root }}{{ cssFile }}" />
    {% endfor %}
    <link rel="stylesheet/less" type="text/css" href="{{ root }}color.less" />
    <style id="nprogress-style">
      #nprogress {
        display: none;
      }
    </style>
    <!--[if lte IE 10]>
      <script src="https://as.alipayobjects.com/g/component/??console-polyfill/0.2.2/index.js,media-match/2.0.2/media.match.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div id="react-content">
      {{ content | safe }}
    </div>
    {% for jsFile in manifest["js"] %}<script src="{{ root }}{{ jsFile }}"></script>
    {% endfor %}
  </body>
</html>
